package com.fs.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.Sto;
import com.fs.vo.Condition;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author 刘伟
 * @fileName ProcurementMapper
 * @date 2024/10/15 9:18
 * @description
 **/
@Mapper
public interface ProcurementMapper extends BaseMapper<Sto> {
    @Select("<script>" +
            "SELECT sto.sto_pro_id, sto.sto_sup_id, sup.sup_name, sto.sto_pay, sto.sto_date, " +
            "sto.sto_actor, sys_role1.role_name AS role_name_actor1, sto.sto_note, " +
            "sto.app_manger_id, sys_role2.role_name AS role_name_actor2, sto.app_passDate, sto.sto_state " +
            "FROM sto " +
            "JOIN sup ON sto.sto_sup_id = sup.sup_id " +
            "JOIN sys_role sys_role1 ON sto.sto_actor = sys_role1.role_id " +
            "JOIN sys_role sys_role2 ON sto.app_manger_id = sys_role2.role_id " +
            "<where>" +
            "<if test='search != null'>" +
            "<if test='search.stoProId != null'>AND sto_pro_id like #{search.stoProId}</if>" +
            "<if test='search.stoSupId != null'>AND sto_sup_id like #{search.stoSupId}</if>" +
            "</if>" +
            "</where>" +
            "</script>")
    List<Sto> getProcurementList(@Param("condition") Condition<Sto> condition);

    @Select("select * from sto where sto_pro_id = #{id}")
    Sto queryProcurementById(@Param("id") Integer id);
}
